package Models;

import DB.DBCheckpoint;
import DB.RowInterface;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;

public class Checkpoint implements RowInterface
{
	private int checkpointNo;
	private int roundNo;
	private double longitude;
	private double latitude;
	private String description = "";

	public Checkpoint()
	{}

	public Checkpoint(double longitude, double latitude)
	{
		this.longitude = longitude;
		this.latitude = latitude;
	}

	public void importData(ResultSet data) throws SQLException
	{
		this.setCheckpointNo(data.getInt("checkpointNo"));
		this.setRoundNo(data.getInt("roundNo"));
		this.setLongitude(data.getDouble("longitude"));
		this.setLatitude(data.getDouble("latitude"));
		this.setDescription(data.getString("description"));
	}

	public HashMap exportData()
	{
		HashMap data = new HashMap();
		data.put("roundNo", getRoundNo());
		data.put("longitude", getLongitude());
		data.put("latitude", getLatitude());
		data.put("description", getDescription());
		return data;
	}

	public void setData(String longitudeS, String latitudeS) throws EmptyValueException, NumberFormatException
	{
		if(!longitudeS.equals("") && !latitudeS.equals(""))
		{
			double longitudeTemp = Double.parseDouble(longitudeS);
			this.setLongitude(longitudeTemp);
			
			double latitudeTemp = Double.parseDouble(latitudeS);
			this.setLatitude(latitudeTemp);
		}
		else
		{
			throw new EmptyValueException();
		}
	}

	public void refreshData()
	{
		Checkpoint checkpoint = new DBCheckpoint().fetchByNo(getCheckpointNo());
		this.setRoundNo(checkpoint.getRoundNo());
		this.setLongitude(checkpoint.getLongitude());
		this.setLatitude(checkpoint.getLatitude());
		this.setDescription(checkpoint.getDescription());
	}

	public int getCheckpointNo()
	{
		return checkpointNo;
	}

	public String getDescription()
	{
		return description;
	}

	public double getLatitude()
	{
		return latitude;
	}

	public double getLongitude()
	{
		return longitude;
	}

	public int getRoundNo()
	{
		return roundNo;
	}

	public void setCheckpointNo(int checkpointNo)
	{
		this.checkpointNo = checkpointNo;
	}

	public void setDescription(String description)
	{
		this.description = description;
	}

	public void setLatitude(double latitude)
	{
		this.latitude = latitude;
	}

	public void setLongitude(double longitude)
	{
		this.longitude = longitude;
	}

	public void setRoundNo(int roundNo)
	{
		this.roundNo = roundNo;
	}
}
